package Algorithm;

public class test4 {
    // 盛最多水的容器
    // 算法原理: 双指针, 核心: 每次去掉高度较小的柱子
    public static void main(String[] args) {
        int[] height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        // 让left和right左右遍历,找出每一次的体积并更新 vmax
        int vmax = -1, left = 0, right = height.length - 1;
        while (left <= right) {
            int wide = right - left;
            int v = Math.min(height[left], height[right]) * wide;
            if (v > vmax) {
                vmax = v;
            }
            // 每次去掉高度较小的柱子
            if (height[left] < height[right]) {
                left++;
            } else {
                right--;
            }
        }
        System.out.println(vmax);
    }
}
